<?php
namespace console\components\task;

use yii\base\BaseObject;
use yii\helpers\Json;

class TaskManage extends BaseObject
{
    public static function checkTask($data)
    {
        $data = Json::decode($data);
        if (isset($data['type']) && in_array($data['type'], \Yii::$app->params['taskType'])) {
            return true;
        }
        return false;
    }

    public static function addTask($data)
    {
        $data = Json::decode($data);
        $class_name = '\\'.__NAMESPACE__.'\Task' . ucfirst($data['type']) . 'Manage';
        if (class_exists($class_name)) {
            return \Yii::createObject([
                'class' => $class_name,
                'data' => $data]);
        }
        return false;
    }
}
